package cn.ekuma.android.driver;

import java.io.IOException;
import java.io.OutputStream;

import android_serialport_api.SerialPort;
import com.openbravo.pos.printer.TicketPrinterException;
import com.openbravo.pos.printer.escpos.PrinterWritter;

public class PrinterWritterCom extends PrinterWritter /* implements SerialPortEventListener */ {
    

    private OutputStream m_out;
    SerialPort mSerialPort;
    
    /** Creates a new instance of PrinterWritterComm */
    public PrinterWritterCom(SerialPort mSerialPort) throws TicketPrinterException {
    	this.mSerialPort=mSerialPort;
    }

	protected void internalWrite(byte[] data) {
		try {
			if(m_out==null)
				m_out=mSerialPort.getOutputStream();
			m_out.write(data);
		} catch (IOException e) {
			 System.err.println(e);
		}
    }
    
    protected void internalFlush() {
        try {  
            if (m_out != null) {
                m_out.flush();
            }
        } catch (IOException e) {
            System.err.println(e);
        }    
    }
    
    protected void internalClose() {
        try {  
            if (m_out != null) {
                m_out.flush();
                m_out.close();
                m_out = null;
                mSerialPort.close();
            }
        } catch (IOException e) {
            System.err.println(e);
        }    
    }
}